package com.example.cadmin.utils;

import cn.hutool.json.JSONUtil;
import com.example.cadmin.Application;
import com.example.cadmin.entity.Host;
import com.example.cadmin.mapper.HostMapper;
import com.example.cadmin.utils.Netty.sendCmd;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 获取温湿度后台定时器
 */
@Slf4j
public class ConnectionStatus {

    /**
     * 获取温湿度
     */
    public void get() throws IOException {
        HostMapper hostMapper = Application.ac.getBean(HostMapper.class);
        sendCmd sendCmd = Application.ac.getBean(sendCmd.class);
        List<Host> hostList = hostMapper.selectList(null);

        for (Host host : hostList) {
            Map<String, String> map = new HashMap<>();
            map.put("cmd", "setting_get");
            map.put("cabinet_id", host.getNumber());
            map.put("setting_name", "board_x");
            String sendMap = JSONUtil.toJsonStr(map);
            sendCmd.send(sendMap,null,host.getIp());
        }
    }
}
